package com.atguigu.jxc.service.impl;

import com.atguigu.jxc.dao.CustomerDao;
import com.atguigu.jxc.entity.Customer;
import com.atguigu.jxc.service.CustomerService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * ClassName: CustomerServiceImpl
 * Description:
 * Date: 2022/1/15 21:13
 *
 * @version:
 * @since JDK 1.8
 */
@Service
public class CustomerServiceImpl implements CustomerService {


    @Autowired
    private CustomerDao customerDao;

    @Override
    public Page<Customer> selectPage(Integer page, Integer rows, String customerName) {
        PageHelper.startPage(page,rows);
        Page<Customer> customerPage =  customerDao.findPage(customerName);

        return customerPage;
    }





    @Override
    public void deleteCustomerByIds(String ids) {

        String[] arr = ids.split(",");
        for (String s : arr) {
            deleteCustomerById(new Integer(s));
        }


    }

    private void deleteCustomerById(Integer customerId) {
        customerDao.deleteCustomerById(customerId);

    }

    @Override
    public void insertOrUpdateCustomer(Customer customer) {

        if(customer.getCustomerId() != null){
            customerDao.UpdateCustomerById(customer);
        }else{
            customerDao.insertCustomer(customer);
        }

    }

    @Override
    public List<Customer> getComboboxList(String q) {
        List<Customer> customerList = customerDao.getComboboxList(q);
        return customerList;
    }




}
